package main.java.model;

import java.util.Observable;

public class Lights extends Observable {
    
    //static final variables to change positions id easier
    private static final int WHITE_ID = 0;
    private static final int GREEN_ID = 1;
    private static final int ORANGE_ID = 2;
    private static final int RED_ID = 3;
	
    private int position;

    /**
     * Constructor Lights
     */
    public Lights() {
        //Set to White
        this.position = WHITE_ID; 
    }
    
    /**
     * Return the position in a string
     * @return String : the position in a string
     */
    public String positionToString() {
        switch (position) {
            case WHITE_ID :
                return "White";
            case GREEN_ID :
                return "Green";
            case ORANGE_ID :
                return "Orange";
            case RED_ID :
                return "Red";
            default :
                return "Default";
        }
    }

    /**
     * Lights' action depending on the change that happened
     * @param position : the change
     */
    public void action(String position) {
        switch (position) {
            case "Up":
            case "Closed":
                //Set to White 
                setPosition(WHITE_ID); 
                break;
            case "Down":
                //Set to Green 
                setPosition(GREEN_ID); 
                break;
            case "Maneuvering":
                //Set to Orange 
                setPosition(ORANGE_ID);
                break;
            case "Failure":
                //Set to Red 
                setPosition(RED_ID); 
                break;
            default:
                break;
        }    
    }

    public int getPosition() {
        return position;
    }

    /**
     * Set Position and notify the main application
     * @param position : the new position
     */
    public void setPosition(int position) {
        this.position = position;
        
        //Setting changes
        setChanged(); 
        //Notify
        notifyObservers(positionToString()); 
    }
}
